<?php

// legge key
$key = $_POST["key"];

// TEMP
$CODE='G535';

$uploaddir = './data/';
//$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$uploadfile = $uploaddir . $CODE.".txt";

$allowed =  array('txt','TXT');
$ext = pathinfo($uploadfile, PATHINFO_EXTENSION);


echo '<pre>';

echo 'CODE:'. $CODE . "\n";
echo 'key:'. $key . "\n";

echo 'working:'. getcwd() . "\n";

if ($key=='' || $key!= md5($CODE)){
	 echo "Chiave non valida .\n";
}else if(!in_array($ext,$allowed) ) {
    echo "errore formato non valido !\n";
} else if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File caricato con successo.\n";
} else {
    echo "errore durante upload!\n";
}
/*
echo 'Alcune informazioni di debug:';
print_r($_FILES);
*/
print "</pre>";

?>